<!-- 表单 》 颜色选择器 -->

<template>
  <el-form-item v-bind="formItem">
    <!-- 标签 -->
    <template v-if="hasLabelSlot" #label>
      <slot name="label" :label="formItem.label">{{ formItem.label }}</slot>
    </template>

    <el-color-picker v-model="model" v-bind="commonProps" @change="emitChange" />
  </el-form-item>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import mixForm from '../mixForm'

const name = 'FormColor'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name,

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [mixForm],

  /**
   * 属性注册 (抽取以便查阅)
   */
  props: CORE.WEB[name],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 公共属性
     */
    commonProps() {
      const { elProps, className, prop, isDisabled, noClear, size, list, showAlpha, colorFormat } = this
      return {
        ...elProps,
        name: prop,
        class: className,
        popperClass: noClear ? `${className}-no-clear` : null,
        disabled: isDisabled,
        size,
        predefine: list,
        showAlpha,
        colorFormat,
      }
    },
  },
}
</script>
